#include "TreeWriter.h"
#include <cstdlib>

void TreeWriter::write(INode* node, IDataWriter* writer)
{
	char choise;
	if((NULL != node->left()) && (NULL != node->right()))
	{
		writer->putChar(3);
		write(node->right(),writer);
		write(node->left(),writer);
	}
	else
		if(NULL != node->left())
		{
			writer->putChar(1);
			write(node->left(),writer);
		}
		else
			if(NULL != node->right())
			{
				writer->putChar(2);
				write(node->right(),writer);
			}
			else
			{
				writer->putChar(0);
				writer->putChar(node->getChar());
			}
}